<?php


namespace app\admin\controller;


use think\Controller;
use think\Db;

class Workflowroval extends Controller
{
    /**
     * 流程模板设计师网站首页，
     * @return mixed
     */
    public function index(){
        $id = input('id');
        $this->assign([
            'id'=> $id
        ]);
       return $this->fetch();
    }



    /**
     * 调取节点属性设置页面
     */
    public function get_data(){
        //节点ID
        $id = input('id');
        //节点基本信息
        $basic = Db::name('wf_process')->find($id);
        $is_form_extend = Db::name('wf_flow')->find($basic['flow_id'])['is_form_extend'];

        //获取相关节点信息---用于下拉显示
        $relevant = Db::name('wf_process')
                    ->where(array('flow_id'=>$basic['flow_id'],'id'=>array('neq',$id)))
                    ->field('id,process_name')
                    ->select();

        //获取子流程列表  --子流程下拉

        //获取审核权限预设列表
        $auto_person = Db::name('wf_auto_person')->field('id,name')->select();

        //操作查询
        $con_sign      = Db::name('wf_con_sign')->where('type','eq','1')->field('type,id,name')->select();
        $con_sign_vsb  = Db::name('wf_con_sign')->where('type','eq','2')->field('type,id,name')->select();
        $con_sign_back = Db::name('wf_con_sign')->where('type','eq','3')->field('type,id,name')->select();

        //数据补全
        $basic = $this->process_repair($basic);
        $this->assign([
            'id'=>$id,  //当前节点ID
            'basic'=>$basic, //节点基础属性
            'relevant'=>$relevant,  //相关节点信息
//            'flow'=>$child_ids,
//            'list'=>$list,  //可选子流程列表
            'auto_person'=>$auto_person, //权限页面--预设方式
            'con_sign'=>$con_sign,
            'con_sign_vsb'=>$con_sign_vsb,
            'con_sign_back'=>$con_sign_back,
            'is_form_extend'=>$is_form_extend,
        ]);
        //echo 防止渲染
        echo $this->fetch();
    }

    /**
     * 数据修补（页面ajax改版优化后删除）
     * @param $basic
     */
    public function process_repair($basic){

        //修正子节点信息
        if(empty($basic['process_to'])){
            $basic['process_to'] = array();

        }else{
            $basic['process_to'] = explode(',',$basic['process_to']);
        }
        //补充节点类型的默认状态
        if(!isset($basic['process_type'])  || $basic['process_type']==''){
            $basic['process_type']='is_step';
        }

//        if(!isset($basic['process_name'])  || $basic['process_name']==''){
//            $basic['process_name']='节点';
//        }
        //补充审核权限预设信息 默认不选择
        if(empty($basic['auto_person'])){
            $basic['auto_person'] = 1;
        }
        //是否允许修改
        if(empty($basic['auto_unlock'])){
            $basic['auto_unlock'] = 1;
        }
        return $basic;
    }
}